<!-- 设备管理-设备页面 -->
<template>
  <div class="app-container" style="margin: 0">
    <px-form v-show="showSearch" ref="queryRef" class="custom-form-ui" :model="queryParams" :inline="true" label-width="90px">
      <px-form-item label="排查计划名称">
        <px-input v-model="queryParams.planName" placeholder="请输入排查计划名称" clearable />
      </px-form-item>
      <px-form-item label="排查类型">
        <px-select v-model="queryParams.checkTypeCode" placeholder="请选择排查类型" clearable style="width: 240px" filterable>
          <px-option v-for="dict in checkTypeCodeList" :key="dict.id" :label="dict.itemName" :value="dict.itemValue" />
        </px-select>
      </px-form-item>
      <px-form-item label="审批状态">
        <px-select v-model="queryParams.approveStatus" placeholder="请选择审批状态" clearable style="width: 240px" filterable>
          <px-option v-for="dict in ApproveStatusList" :key="dict.code" :label="dict.name" :value="dict.code" />
        </px-select>
      </px-form-item>
      <px-form-item label="执行状态">
        <px-select v-model="queryParams.taskStatus" placeholder="请选择执行状态" clearable style="width: 240px" filterable>
          <px-option v-for="dict in PlanStatusList" :key="dict.code" :label="dict.name" :value="dict.code" />
        </px-select>
      </px-form-item>
      <px-form-item label="创建人">
        <px-select v-model="queryParams.createrId" placeholder="请选择创建人" clearable style="width: 240px" filterable>
          <px-option v-for="dict in userList" :key="dict.createrId" :label="dict.nickName" :value="dict.userId" />
        </px-select>
      </px-form-item>
      <px-button style="margin-top: -17px" type="primary" icon="" @click="handleQuery('search')">搜索</px-button>
      <px-button style="margin-top: -17px" icon="" @click="resetQuery">重置</px-button>
    </px-form>

    <px-row :gutter="10" class="mb8">
      <px-col :span="1.5">
        <px-button type="primary" icon="" @click="handleAdd">新增排查计划</px-button>
      </px-col>
    </px-row>

    <px-table
      v-if="!equipopen && !equipopenDetail"
      v-loading="loading"
      :data="typeList"
      height="calc(100vh - 369px)"
      show-overflow-tooltip
      border
      @selection-change="handleSelectionChange"
    >
      <px-table-column label="计划编号" prop="planNum">
        <template #default="scope">
          <span>{{ scope.row.planNum ? scope.row.planNum : "-" }}</span>
        </template>
      </px-table-column>
      <px-table-column label="排查计划名称" prop="planName">
        <template #default="scope">
          <span>{{ scope.row.planName ? scope.row.planName : "-" }}</span>
        </template>
      </px-table-column>

      <px-table-column label="执行状态" prop="taskStatusName">
        <template #default="scope">
          <span>{{ scope.row.taskStatusName ? scope.row.taskStatusName : "-" }}</span>
        </template>
      </px-table-column>

      <px-table-column label="审批状态" width="160" prop="approveStatusName">
        <template #default="scope">
          <span>{{ scope.row.approveStatusName ? scope.row.approveStatusName : "-" }}</span>
        </template>
      </px-table-column>

      <px-table-column label="排查类型" prop="checkTypeName">
        <template #default="scope">
          <span>{{ scope.row.checkTypeName ? scope.row.checkTypeName : "-" }}</span>
        </template>
      </px-table-column>
      <!-- <px-table-column label="排查内容" prop="createTime">
        <template #default="scope">
          <span>{{ scope.row.createTime ? scope.row.createTime : "-" }}</span>
        </template>
      </px-table-column> -->
      <px-table-column label="开始日期" prop="scheduleStartTime">
        <template #default="scope">
          <span>{{ scope.row.scheduleStartTime ? scope.row.scheduleStartTime : "-" }}</span>
        </template>
      </px-table-column>
      <px-table-column label="结束日期" prop="scheduleEndTime">
        <template #default="scope">
          <span>{{ scope.row.scheduleEndTime ? scope.row.scheduleEndTime : "-" }}</span>
        </template>
      </px-table-column>
      <px-table-column label="创建人" prop="createrName">
        <template #default="scope">
          <span>{{ scope.row.createrName ? scope.row.createrName : "-" }}</span>
        </template>
      </px-table-column>
      <px-table-column label="创建日期" prop="createTime">
        <template #default="scope">
          <span>{{ scope.row.createTime ? scope.row.createTime : "-" }}</span>
        </template>
      </px-table-column>
      <px-table-column fixed="right" label="操作" align="center" width="140">
        <template #default="scope">
          <!-- <px-button link type="primary" @click="handleDetail(scope.row.checkScopeId)">
            <px-tooltip class="box-item" content="详情" placement="top">
              <px-icon><Tickets /></px-icon> </px-tooltip
          ></px-button> -->
          <px-button v-if="scope.row.status != 'INVALID'" link type="primary" @click="handleEditor(scope.row.checkScopeId)">
            <px-tooltip class="box-item" content="变更" placement="top">
              <p><biangeng /></p> </px-tooltip
          ></px-button>
          <px-button v-if="scope.row.status != 'INVALID'" link type="danger" @click="handleDelete(scope.row)"
            ><px-tooltip class="box-item" content="终止" placement="top">
              <px-icon><StopCircle /></px-icon> </px-tooltip
          ></px-button>
        </template>
      </px-table-column>
      <template #empty>
        <px-empty :image-size="150" />
      </template>
    </px-table>

    <pagination
      v-if="!equipopen && !equipopenDetail"
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      style="margin-bottom: -10px"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->

    <px-scrollbar v-if="equipopen" class="editorEquip">
      <px-button style="margin-left: 24px" type="primary" :icon="ArrowLeft" @click="cancel">返回</px-button>
      <div class="px-descriptions__title" style="margin: 20px 0 0 20px">基本信息</div>
      <px-row style="padding: 20px">
        <px-col :span="24">
          <px-descriptions class="margin-top" :column="3" border>
            <px-descriptions-item>
              <template #label>
                <div class="cell-item">排查范围名称:</div>
              </template>
              {{ equipdata.scopeName }}
            </px-descriptions-item>
          </px-descriptions>
        </px-col>
        <px-col :span="24">
          <px-descriptions class="center2" :column="3" border>
            <px-descriptions-item>
              <template #label>
                <div class="cell-item">排查范围说明:</div>
              </template>
              {{ equipdata.description }}
            </px-descriptions-item>
          </px-descriptions>
        </px-col>
      </px-row>
      <div class="px-descriptions__title" style="margin: 20px 0 0 20px">排查范围</div>
      <div style="padding: 0 20px 20px">
        <px-table style="margin-top: 20px" :data="equipdata.locations" height="480px" border>
          <px-table-column label="序号">
            <template #default="scope">
              <px-tooltip :content="scope.row.id" placement="top" effect="light">
                <span>{{ scope.$index + 1 || "--" }}</span>
              </px-tooltip>
            </template>
          </px-table-column>

          <px-table-column label="地点名称" prop="attributeName">
            <template #default="scope">
              <px-tooltip :content="scope.row.name" placement="top" effect="light">
                <span>{{ scope.row }}</span>
              </px-tooltip>
            </template>
          </px-table-column>
        </px-table>
      </div>
    </px-scrollbar>
    <px-scrollbar v-if="equipopenDetail" class="addEquip">
      <px-button style="margin-left: 24px" type="primary" :icon="ArrowLeft" @click="equipopenDetailcancel">返回</px-button>
      <px-form
        ref="detailruleFormRef"
        :disabled="fromdisable"
        :rules="rules"
        :model="equipdata"
        :inline="true"
        class="demo-form-inline"
        label-width="160px"
      >
        <div
          class="box-card1"
          :style="{
            height: jibenxinxiFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setqingdanFlg()">
            <div class="card-title">基本信息</div>
            <div class="card-main">
              <px-icon v-if="!jibenxinxiFlg"><ArrowDown /></px-icon>
              <px-icon v-else><ArrowUp /></px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="排查计划名称" prop="planName">
                  <px-input
                    v-model="equipdata.planName"
                    style="width: calc(100% - 100px)"
                    placeholder="请输入排查范围名称"
                    clearable
                  /> </px-form-item
              ></px-col>
              <px-col :span="12">
                <px-form-item label="排查类型" prop="checkTypeCode">
                  <px-select v-model="equipdata.checkTypeCode" placeholder="请选择排查类型" clearable style="width: calc(100% - 100px)" filterable>
                    <px-option
                      v-for="dict in checkTypeCodeList"
                      :key="dict.id"
                      :label="dict.itemName"
                      :value="dict.itemValue"
                    /> </px-select></px-form-item
              ></px-col>
            </px-row>
            <px-row>
              <px-col :span="12">
                <px-form-item label="排查范围" prop="checkScopeId">
                  <px-select
                    v-model="equipdata.checkScopeId"
                    placeholder="请选择排查类型"
                    clearable
                    style="width: calc(100% - 100px)"
                    filterable
                    @change="setlocationsList"
                  >
                    <px-option v-for="dict in scopequeryList" :key="dict.checkScopeId" :label="dict.scopeName" :value="dict.checkScopeId" />
                  </px-select> </px-form-item
              ></px-col>
              <px-col :span="12">
                <px-form-item label="排查表" prop="checkContentId">
                  <px-select
                    v-model="equipdata.checkContentId"
                    placeholder="请选择排查表"
                    clearable
                    style="width: calc(100% - 100px)"
                    filterable
                    @change="setcontentList"
                  >
                    <px-option
                      v-for="dict in contentqueryList"
                      :key="dict.checkContentId"
                      :label="dict.contentName"
                      :value="dict.checkContentId"
                    /> </px-select></px-form-item
              ></px-col>
            </px-row>
            <px-row>
              <px-col :span="12">
                <px-form-item label="科室" prop="classroomCodes">
                  <px-select
                    v-model="equipdata.classroomCodes"
                    placeholder="请选择科室(可多选)"
                    clearable
                    multiple
                    collapse-tags
                    collapse-tags-tooltip
                    style="width: calc(100% - 100px)"
                    filterable
                  >
                    <px-option
                      v-for="dict in listAllClassRoomsList"
                      :key="dict.id"
                      :label="dict.className"
                      :value="dict.classCode"
                    /> </px-select></px-form-item
              ></px-col>
              <px-col :span="12">
                <px-form-item label="任务分配" prop="assignType">
                  <px-radio-group v-model="equipdata.assignType" class="ml-4">
                    <px-radio label="POSITION" size="large">到岗位</px-radio>
                    <px-radio label="EMPLOYEE" size="large">到人员</px-radio>
                  </px-radio-group></px-form-item
                ></px-col
              >
            </px-row>
            <px-row>
              <px-col :span="12">
                <px-form-item label="组织" prop="groupId">
                  <px-select v-model="equipdata.groupId" placeholder="请选择排查类型" clearable style="width: calc(100% - 100px)" filterable>
                    <px-option
                      v-for="dict in findByParentIdList"
                      :key="dict.id"
                      :label="dict.deptName"
                      :value="dict.deptId"
                    /> </px-select></px-form-item
              ></px-col>
              <px-col v-if="equipdata.assignType == 'POSITION'" :span="12">
                <px-form-item label="选择到岗位" prop="positionIds">
                  <px-select
                    v-model="equipdata.positionIds"
                    multiple
                    collapse-tags
                    collapse-tags-tooltip
                    placeholder="请选择岗位"
                    clearable
                    style="width: calc(100% - 100px)"
                    filterable
                  >
                    <px-option
                      v-for="dict in listPositionOptionList"
                      :key="dict.id"
                      :label="dict.positionName"
                      :value="dict.positionId"
                    /> </px-select></px-form-item
              ></px-col>
              <px-col v-if="equipdata.assignType == 'EMPLOYEE'" :span="12">
                <px-form-item label="选择到人员" prop="employeeIds">
                  <px-select
                    v-model="equipdata.employeeIds"
                    multiple
                    collapse-tags
                    collapse-tags-tooltip
                    placeholder="请选择人员"
                    clearable
                    style="width: calc(100% - 100px)"
                    filterable
                  >
                    <px-option
                      v-for="dict in userList"
                      :key="dict.createrId"
                      :label="dict.nickName"
                      :value="dict.nickName"
                    /> </px-select></px-form-item
              ></px-col>
            </px-row>
            <!-- <px-row>
              <px-col :span="24">
                <px-form-item label="排查计划说明" prop="description">
                  <px-input
                    v-model="equipdata.description"
                    style="width: calc(100% - 100px)"
                    :autosize="{ minRows: 5, maxRows: 6 }"
                    type="textarea"
                    placeholder="请输入排查计划说明"
                    clearable
                  />
                </px-form-item>
              </px-col>
            </px-row> -->
          </div>
        </div>
        <div
          class="box-card2"
          :style="{
            height: moxingshezhiFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setmoxingshezhiFlg()">
            <div class="card-title">执行周期</div>
            <div class="card-main">
              <px-icon v-if="!moxingshezhiFlg"><ArrowDown /></px-icon>
              <px-icon v-else><ArrowUp /></px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="执行方式" prop="scheduleType">
                  <px-select v-model="equipdata.scheduleType" placeholder="请选择执行方式" clearable style="width: calc(100% - 100px)" filterable>
                    <px-option v-for="dict in scheduleTypeList" :key="dict.value" :label="dict.name" :value="dict.value" />
                  </px-select> </px-form-item
              ></px-col>
              <px-col :span="12">
                <px-form-item label="执行时间" style="width: calc(100% - 100px)" prop="timevalue">
                  <px-date-picker
                    v-model="equipdata.timevalue"
                    type="datetimerange"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    format="YYYY-MM-DD HH:mm:ss"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    :default-time="defaultTime" /></px-form-item
              ></px-col>
            </px-row>
            <px-row>
              <px-col :span="12">
                <px-form-item label="排查周期" prop="interval">
                  每
                  <px-input-number v-model="equipdata.scheduleCron.interval" style="width: 100px" class="mx-4" :min="1" controls-position="right" />
                  <px-select
                    v-model="equipdata.scheduleCron.frequent"
                    placeholder=""
                    clearable
                    style="width: 109px"
                    filterable
                    @change="clearfrequent"
                  >
                    <px-option v-for="dict in frequentList" :key="dict.value" :label="dict.name" :value="dict.value" />
                  </px-select>
                  <span v-if="equipdata.scheduleCron.frequent != 'Y'" class="mx-4">的</span>
                  <px-select
                    v-if="equipdata.scheduleCron.frequent == 'D'"
                    v-model="equipdata.scheduleCron.values"
                    placeholder=""
                    clearable
                    style="width: calc(100% - 400px)"
                    filterable
                    multiple
                    collapse-tags
                    collapse-tags-tooltip
                  >
                    <px-option v-for="dict in daylist" :key="dict" :label="dict + '时'" :value="dict" />
                  </px-select>
                  <px-select
                    v-if="equipdata.scheduleCron.frequent == 'W'"
                    v-model="equipdata.scheduleCron.values"
                    placeholder=""
                    clearable
                    style="width: calc(100% - 400px)"
                    filterable
                    multiple
                    collapse-tags
                    collapse-tags-tooltip
                  >
                    <px-option v-for="dict in weekList" :key="dict" :label="'周' + dict" :value="dict" />
                  </px-select>
                  <px-select
                    v-if="equipdata.scheduleCron.frequent == 'M'"
                    v-model="equipdata.scheduleCron.values"
                    placeholder=""
                    clearable
                    style="width: calc(100% - 400px)"
                    filterable
                    multiple
                    collapse-tags
                    collapse-tags-tooltip
                  >
                    <px-option v-for="dict in monthList" :key="dict" :label="dict + '日'" :value="dict" />
                  </px-select> </px-form-item
              ></px-col>
              <px-col :span="12">
                <px-form-item label=" 宽泛期">
                  <px-input-number v-model="equipdata.scheduleCron.extendTime" style="width: 100px" :min="1" controls-position="right" />
                  <px-select
                    v-model="equipdata.scheduleCron.extendUnit"
                    placeholder="宽泛期单位"
                    class="mx-4"
                    clearable
                    style="width: 109px"
                    filterable
                  >
                    <px-option v-for="dict in extendUnitList" :key="dict.value" :label="dict.name" :value="dict.value" />
                  </px-select> </px-form-item
              ></px-col>
            </px-row>
          </div>
        </div>
        <div
          v-if="contentList.length > 0 || locationsList.length > 0"
          class="box-card2"
          :style="{
            height: qingdanList == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setqingdanListFlg()">
            <div class="card-title">排查内容</div>
            <div class="card-main">
              <px-icon v-if="!qingdanList"><ArrowDown /></px-icon>
              <px-icon v-else><ArrowUp /></px-icon>
            </div>
          </div>
          <div class="form-div" style="padding: 20px 32px">
            <div v-if="contentList.length > 0" class="card-title" style="margin-bottom: 20px">排查表</div>
            <div v-if="contentList.length > 0" class="form-table">
              <px-table style="margin-top: 20px" :data="contentList" height="280px" border>
                <px-table-column label="序号">
                  <template #default="scope">
                    <px-tooltip :content="scope.row.id" placement="top" effect="light">
                      <span>{{ scope.$index + 1 || "--" }}</span>
                    </px-tooltip>
                  </template>
                </px-table-column>

                <px-table-column label="排查内容" prop="attributeName">
                  <template #default="scope">
                    <px-tooltip :content="scope.row.content" placement="top" effect="light">
                      <span>{{ scope.row.content }}</span>
                    </px-tooltip>
                  </template>
                </px-table-column>
              </px-table>
            </div>
            <div v-if="locationsList.length > 0" class="card-title" style="margin: 20px 0">排查范围</div>
            <div v-if="locationsList.length > 0" class="form-table">
              <px-table style="margin-top: 20px" :data="locationsList" height="280px" border>
                <px-table-column label="序号">
                  <template #default="scope">
                    <px-tooltip :content="scope.row.id" placement="top" effect="light">
                      <span>{{ scope.$index + 1 || "--" }}</span>
                    </px-tooltip>
                  </template>
                </px-table-column>

                <px-table-column label="地点名称" prop="attributeName">
                  <template #default="scope">
                    <px-tooltip :content="scope.row.name" placement="top" effect="light">
                      <span>{{ scope.row }}</span>
                    </px-tooltip>
                  </template>
                </px-table-column>
              </px-table>
            </div>
          </div>
        </div>
      </px-form>
    </px-scrollbar>
    <div v-if="equipopenDetail" class="px-dialog-footer">
      <px-button @click="equipopenDetailcancel">取消</px-button>
      <px-button v-if="fromdisable" type="primary" @click="equipopenDetailcancel">关闭</px-button>
      <px-button v-else type="primary" :disabled="photoStatusFlag || fileStatusFlag" @click="equipopenDetailsubmitForm(detailruleFormRef)"
        >保存</px-button
      >
    </div>
  </div>
</template>

<script setup name="Dict" lang="ts">
// import useDictStore from '@/store/modules/dict'
defineOptions({
  name: "SystemDataDict"
});
const defaultProps = {
  children: "children",
  label: "name",
  value: "name"
};
const emits = defineEmits(["addDiv", "getTotal"]);

import biangeng from "@/assets/svg/biangeng.svg?component";
import { ArrowLeft } from "@px-ui/icons-vue";
import { useRoute } from "vue-router";
import { PxMessage, PxMessageBox } from "px-ui";
import { getCurrentInstance, ref, toRefs, reactive, onMounted } from "vue";
import { getToken } from "@/utils/auth";
import { queryChildByTypeCodeAndItemValue } from "@/api/waterClass";
import { contentgetById } from "@/api/scope";
import {
  userlistPage,
  planqueryPage,
  basiclistPlanStatus,
  basiclistApproveStatus,
  deptfindByParentId,
  positionlistPositionOption,
  basiclistAllClassRooms,
  plansubmit,
  planupdate,
  planterminal
} from "@/api/checkProject";
import { contentquery, scopequery, scopegetById } from "@/api/scope";
const positionform = reactive({
  positionId: ""
});
const jibenxinxiFlg = ref(true);
const setqingdanFlg = () => {
  jibenxinxiFlg.value = !jibenxinxiFlg.value;
};
const jiqicanshuFlg = ref(true);
const setjiqicanshuFlg = () => {
  jiqicanshuFlg.value = !jiqicanshuFlg.value;
};
const shebeitaizhangFlg = ref(true);
const setshebeitaizhangFlg = () => {
  shebeitaizhangFlg.value = !shebeitaizhangFlg.value;
};
const moxingshezhiFlg = ref(true);
const setmoxingshezhiFlg = () => {
  moxingshezhiFlg.value = !moxingshezhiFlg.value;
};
const qingdanList = ref(true);
const setqingdanListFlg = () => {
  qingdanList.value = !qingdanList.value;
};
const positionVisible = ref(false);
const handledelAddPosition = () => {
  positionform.positionId = "";
  positionVisible.value = true;
};

const route = useRoute();
onMounted(() => {
  if (route.query.equipmentId) {
    handleDetail(route.query.equipmentId);
  }
});
const { proxy }: any = getCurrentInstance();

const typeList = ref([]);
const detailruleFormRef = ref();
const equipopen = ref(false);
const equipopenDetail = ref(false);
const fromdisable = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const dateRange = ref([]);

// 图片是否上传完，是否可以保存
const savePhotoStatus1 = val => {
  console.log(val);
  photoStatusFlag.value = val;
};
const savePhotoStatus2 = val => {
  photoStatusFlag.value = val;
};
const savePhotoStatus3 = val => {
  photoStatusFlag.value = val;
};
const savePhotoStatus4 = val => {
  photoStatusFlag.value = val;
};
const defaultTime: [Date, Date] = [new Date(2000, 1, 1, 0, 0, 1), new Date(2000, 1, 1, 23, 59, 59)];
const scheduleTypeList = [
  {
    name: "周期时间",
    value: "PRRIOD"
  },
  {
    name: "固定时间",
    value: "FIX"
  }
];
const frequentList = [
  {
    name: "天",
    value: "D"
  },
  {
    name: "周",
    value: "W"
  },
  {
    name: "月",
    value: "M"
  }
];
const daylist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24];
const weekList = [1, 2, 3, 4, 5, 6, 7];
const monthList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
const extendUnitList = [
  {
    name: "小时",
    value: "H "
  },
  {
    name: "天",
    value: "D "
  }
];
const clearfrequent = () => {
  equipdata.value.scheduleCron.values = "";
};

const setlocationsList = async val => {
  const data = await scopegetById({ checkScopeId: val });
  locationsList.value = data.locations;
};
const setcontentList = async val => {
  const data = await contentgetById({ checkContentId: val });
  contentList.value = data.content;
};
const buttonTitle = ref("");
const data = reactive({
  checkTypeCodeList: [],
  storeList: [],
  sellList: [],
  transportCompanyList: [],
  receiveCompanyList: [],
  typeIdList: [],
  categoryList: [],
  equipmentTypeList: [],
  positionList: [],
  equipmentDeptList: [],
  modelIdList: [],
  form: {},
  photoStatusFlag: false,
  fileStatusFlag: false,
  rediusList: [],
  userList: [],
  ApproveStatusList: [],
  PlanStatusList: [],
  contentqueryList: [],
  scopequeryList: [],
  findByParentIdList: [],
  listPositionOptionList: [],
  listAllClassRoomsList: [],
  locationsList: [],
  contentList: [],
  equipdata: {
    planName: "",
    checkTypeCode: "",
    checkScopeId: "",
    checkContentId: "",
    groupId: "",
    classroomCodes: [],
    assignType: "",
    positionIds: [],
    employeeIds: [],
    scheduleType: "",
    scheduleStartTime: "",
    scheduleEndTime: "",
    scheduleCron: {
      interval: "",
      frequent: "",
      values: [],
      extendTime: "",
      extendUnit: ""
    },
    createrId: "",
    planId: "",
    timevalue: []
  },
  queryParams: {
    orderByColumn: "",
    isAsc: "",
    planName: "",
    checkTypeCode: "",
    approveStatus: "",
    taskStatus: "",
    createrId: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 20
  },
  rules: {
    planName: [{ required: true, message: "排查计划名称不能为空", trigger: "blur" }],
    checkTypeCode: [{ required: true, message: "排查类型不能为空", trigger: "change" }],
    checkScopeId: [{ required: true, message: "排查范围不能为空", trigger: "change" }],
    checkContentId: [{ required: true, message: "排查表不能为空", trigger: "change" }],
    classroomCodes: [{ required: true, message: "科室不能为空", trigger: "change" }],
    assignType: [{ required: true, message: "任务分配不能为空", trigger: "change" }],
    timevalue: [{ required: true, message: "执行时间不能为空", trigger: "change" }]
  },
  headers: {
    Authorization: "Bearer " + getToken().accessToken || ""
  },
  moduleName: "",
  dialogImageUrl: "",
  imageVisible: false
});

const {
  checkTypeCodeList,
  queryParams,
  form,
  rules,
  equipdata,
  equipmentTypeList,
  modelIdList,
  photoStatusFlag,
  fileStatusFlag,
  positionList,
  userList,
  ApproveStatusList,
  PlanStatusList,
  contentqueryList,
  scopequeryList,
  findByParentIdList,
  listPositionOptionList,
  listAllClassRoomsList,
  contentList,
  locationsList
} = toRefs(data);

const getqueryCategoryList = () => {
  queryChildByTypeCodeAndItemValue({ typeCode: "deficiency_check_type" }).then((response: any) => {
    //console.log(response);
    checkTypeCodeList.value = response;
  });

  userlistPage({}).then((response: any) => {
    userList.value = response;
    console.log(response);
  });
  basiclistPlanStatus({}).then((response: any) => {
    PlanStatusList.value = response;
    console.log(response);
  });
  basiclistApproveStatus({}).then((response: any) => {
    ApproveStatusList.value = response;
    console.log(response);
  });
  contentquery({
    orderByColumn: "",
    isAsc: "",
    checkContentId: "",
    contentName: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 999
  }).then((response: any) => {
    console.log(response);
    // total2.value = response.total;
    contentqueryList.value = response.data;
  });
  scopequery({
    orderByColumn: "",
    isAsc: "",
    scopeName: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 999
  }).then((response: any) => {
    console.log(response);
    // total2.value = response.total;
    scopequeryList.value = response.data;
  });
  deptfindByParentId({ pageNum: 1, pageSize: 999 }).then((response: any) => {
    console.log(response);
    // total2.value = response.total;
    findByParentIdList.value = response;
  });
  positionlistPositionOption({ deptId: equipdata.value.groupId }).then((response: any) => {
    console.log(response);
    // total2.value = response.total;
    listPositionOptionList.value = response;
  });
  basiclistAllClassRooms().then((response: any) => {
    console.log(response);
    // total2.value = response.total;
    listAllClassRoomsList.value = response;
  });
};
getqueryCategoryList();
function getList() {
  loading.value = true;
  planqueryPage(queryParams.value).then((response: any) => {
    typeList.value = response.data;
    total.value = response.total;
    emits("getTotal", response.total);
    loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  equipopen.value = false;
}
function equipopenDetailcancel() {
  emits("addDiv", true);
  equipopenDetail.value = false;
}
/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    dictionaryName: undefined,
    dictionaryType: undefined,
    status: "VALID",
    remarks: undefined
  };
  proxy.resetForm("dictRef");
}
/** 搜索按钮操作 */
function handleQuery(type) {
  if (type == "search") {
    queryParams.value.pageNum = 1;
  }
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value = {
    pageNum: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    orderByColumn: "",
    isAsc: "",
    planName: "",
    checkTypeCode: "",
    approveStatus: "",
    taskStatus: "",
    createrId: "",
    orderBy: ""
  };
  dateRange.value = [];
  handleQuery("reset");
}

/** 新增按钮操作 */
function handleAdd() {
  emits("addDiv", false);
  buttonTitle.value = "新增";
  jibenxinxiFlg.value = true;
  jiqicanshuFlg.value = true;
  shebeitaizhangFlg.value = true;
  moxingshezhiFlg.value = true;
  equipopenDetail.value = true;
  fromdisable.value = false;
  equipmentTypeList.value = [];
  modelIdList.value = [];
  equipdata.value = {
    planName: "",
    checkTypeCode: "",
    checkScopeId: "",
    checkContentId: "",
    groupId: "",
    classroomCodes: [],
    assignType: "POSITION",
    positionIds: [],
    employeeIds: [],
    scheduleType: "",
    scheduleStartTime: "",
    scheduleEndTime: "",
    scheduleCron: {
      interval: 1,
      frequent: "D",
      values: [],
      extendTime: "",
      extendUnit: ""
    },
    createrId: "",
    planId: ""
  };
  locationsList.value = [];
  contentList.value = [];
}

const handleDetail = async val => {
  emits("addDiv", false);
  jibenxinxiFlg.value = true;
  jiqicanshuFlg.value = true;
  shebeitaizhangFlg.value = true;
  moxingshezhiFlg.value = true;
  const data = await scopegetById({ checkScopeId: val });
  //console.log(data);

  equipopen.value = true;
  // equipopenDetail.value = true;
  fromdisable.value = true;
  equipdata.value = data;
  equipdata.value.timevalue = [data.scheduleStartTime, data.scheduleEndTime];
};

const handleEditor = async val => {
  emits("addDiv", false);
  buttonTitle.value = "编辑";
  jibenxinxiFlg.value = true;
  jiqicanshuFlg.value = true;
  shebeitaizhangFlg.value = true;
  moxingshezhiFlg.value = true;

  const data = await scopegetById({ checkScopeId: val });
  // console.log(data);
  equipopenDetail.value = true;
  fromdisable.value = false;
  equipdata.value = data;
  equipdata.value.timevalue = [data.scheduleStartTime, data.scheduleEndTime];
};
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 提交按钮 */

const equipopenDetailsubmitForm = async (formEl: any) => {
  if (!formEl) return;
  await formEl.validate(async valid => {
    if (valid) {
      const params = {
        planName: equipdata.value.planName,
        checkTypeCode: equipdata.value.checkTypeCode,
        checkScopeId: equipdata.value.checkScopeId,
        checkContentId: equipdata.value.checkContentId,
        groupId: equipdata.value.groupId,
        classroomCodes: equipdata.value.classroomCodes,
        assignType: equipdata.value.assignType,
        positionIds: equipdata.value.positionIds,
        employeeIds: equipdata.value.employeeIds,
        scheduleType: equipdata.value.scheduleType,
        scheduleStartTime: equipdata.value.timevalue[0],
        scheduleEndTime: equipdata.value.timevalue[1],
        scheduleCron: {
          interval: equipdata.value.scheduleCron.interval,
          frequent: equipdata.value.scheduleCron.frequent,
          values: equipdata.value.scheduleCron.values,
          extendTime: equipdata.value.scheduleCron.extendTime,
          extendUnit: equipdata.value.scheduleCron.extendUnit
        },
        createrId: equipdata.value.createrId,
        planId: equipdata.value.planId
      };
      if (buttonTitle.value == "新增") {
        plansubmit(params).then((response: any) => {
          PxMessage({
            message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
            type: "success"
          });
          resetQuery();
          equipopenDetail.value = false;
          emits("addDiv", true);
        });
      } else {
        planupdate(params).then((response: any) => {
          PxMessage({
            message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
            type: "success"
          });
          resetQuery();
          equipopenDetail.value = false;
          emits("addDiv", true);
        });
      }
    }
  });
};
/** 删除按钮操作 */
function handleDelete(row) {
  PxMessageBox.confirm('是否确认终止"' + row.planName + '"？', "温馨提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    draggable: true
  })
    .then(async () => {
      const data = await planterminal({ planId: row.planId });
      PxMessage({
        message: "终止成功",
        type: "success"
      });
      getList();
    })
    .catch(() => {});
}

getList();
</script>
<style scoped lang="scss">
.addEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.editorEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.px-dialog-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 2002;
  width: 100%;
  height: 50px;
  padding-top: 10px;
  padding-right: 34px;
  text-align: right;
  background: white;
  box-shadow: 0 0 10px 0 rgb(0 0 0 / 16%);
}

.card-header {
  min-height: 40px;
  padding: 14px 15px 7px !important;
  cursor: pointer;
  user-select: none;
  background: #e7eefb;
}

.card-title {
  float: left;
  line-height: 14px;
}

.card-main {
  float: left;
  margin: -3px 8px 0 5px;
  cursor: pointer;
}

.box-card1 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card2 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card3 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card4 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.demo-form-inline {
  .px-input {
    --px-input-width: calc(100% - 100px);
  }

  .px-form-item {
    width: 100%;
  }

  .px-textarea__inner {
    width: calc(100% - 100px) !important;
  }

  .px-form-item__label {
    font-weight: 400 !important;
  }
}

.form-div {
  padding: 24px;

  .px-row {
    margin-bottom: 16px;
  }
}

.px-icon {
  font-size: 16px !important;
}

:deep(.px-tabs__header) {
  // padding-left: 6px !important;
}

:deep(.px-tabs--top .px-tabs__item.is-top.is-active) {
  border: none;

  .pane-bottom {
    line-height: 30px;
    border-bottom: 2px solid #3b82f6;
  }
}

:deep(.px-tabs .px-tabs__item) {
  .pane-bottom {
    line-height: 30px;
  }
}

.pane-line {
  position: absolute;
  top: 12px;
  right: 0;
  height: 15px;
  color: #dcdcdc;
  border-left: 1px solid #dcdcdc;
}

:deep(.custom-form-ui .px-form-item) {
  width: 250px !important;
}

:deep(.px-upload-list--picture-card .px-upload-list__item) {
  width: 96px;
  height: 96px;
}

.filename {
  position: absolute;
  bottom: -30px;
  width: 96px;
  overflow: hidden;
  color: rgb(166 167 172);
  text-overflow: ellipsis;
  white-space: nowrap;
}

:deep(.px-descriptions__label.px-descriptions__cell.is-bordered-label) {
  width: 166px;
  background: #e7eefb;
  border: 1px solid #dfdfdf;
}

:deep(.px-descriptions__body .px-descriptions__table.is-bordered .px-descriptions__cell) {
  border: 1px solid #dfdfdf;
}

.cell-item {
  text-align: right;
}

:deep(.px-table__header) {
  thead {
    tr {
      background-color: #e7eefb !important;

      th {
        font-size: 13px;
        font-weight: bold;
        color: #000;
        background-color: #e7eefb !important;
      }
    }
  }
}

:deep(.px-table--isfixedHeader .px-table__header-wrapper .px-table-fixed-column--right) {
  background-color: #e7eefb !important;
}

.center2 {
  :deep(.px-descriptions__body) {
    table {
      border-left: none;

      .is-bordered-label {
        border-top: none !important;
        border-left: none !important;
      }

      .is-bordered-content {
        border-top: none !important;
      }
    }
  }
}
</style>
